<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>收货地址管理</title>

    <!-- Google Font: Source Sans Pro -->
    <link rel="stylesheet" href="../../plugins/fontawesome-free/css/all.min.css">

    <link rel="stylesheet" href="../../dist/css/adminlte.min.css">
    <script src="../../dist/js/axios.js"></script>
    <script src="../../dist/js/vue.js"></script>
    <style>
        [v-cloak] {
            display: none;
        }
    </style>
</head>
<body class="hold-transition sidebar-mini">
<div class="wrapper" id="app">
    <!-- Navbar -->
    <!-- Navbar -->
    <nav class="main-header navbar navbar-expand navbar-white navbar-light">
        <!-- Left navbar links -->
        <ul class="navbar-nav">
            <li class="nav-item">
                <a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
            </li>
            <li class="nav-item d-none d-sm-inline-block">
                <a href="#" class="nav-link">首页</a>
            </li>
            <li class="nav-item d-none d-sm-inline-block">
                <a href="#" class="nav-link">联系</a>
            </li>
        </ul>

        <!-- SEARCH FORM -->
        <form class="form-inline ml-3">
            <div class="input-group input-group-sm">
                <input class="form-control form-control-navbar" type="search" placeholder="搜索" aria-label="Search">
                <div class="input-group-append">
                    <button class="btn btn-navbar" type="submit">
                        <i class="fas fa-search"></i>
                    </button>
                </div>
            </div>
        </form>

        <!-- Right navbar links -->
        <ul class="navbar-nav ml-auto">
            <!-- Messages Dropdown Menu -->
            <!-- Notifications Dropdown Menu -->
            <li class="nav-item">
                <a class="nav-link" data-widget="fullscreen" href="#" role="button">
                    <i class="fas fa-expand-arrows-alt"></i>
                </a>
            </li>
        </ul>
    </nav>
    <aside class="main-sidebar sidebar-collapse sidebar-dark-primary elevation-4">
        <!-- Brand Logo -->
        <a href="" class="brand-link">
            <img src="../../dist/img/home.png" alt="AdminLTE Logo" class="brand-image img-circle elevation-3"
                 style="opacity: .8">
            <span class="brand-text font-weight-light">MALL</span>
        </a>
        <!-- Sidebar -->
        <div class="sidebar">
            <!-- Sidebar user panel (optional) -->
            <div class="user-panel mt-3 pb-3 mb-3 d-flex">
                <div class="image">
                    <label for="adminAvatar">
                        <img :src="currentUser.avatar" class="img-circle elevation-2" alt="User Image">
                    </label>
                    <input multiple id="adminAvatar" hidden type="file" name="file" value="上传头像"
                           @change="uploadAdminAvatar"/>
                </div>
                <div class="info">
                    <a href="" class="d-block">{{currentUser.username}}</a>
                </div>
            </div>
            <!-- Sidebar Menu -->
            <nav class="mt-2">
                <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu"
                    data-accordion="false">
                    <!-- Add icons to the links using the .nav-icon class
                         with font-awesome or any other icon font library -->
                    <li class="nav-item menu-open">
                        <a href="#" class="nav-link active">
                            <i class="nav-icon fas fa-tachometer-alt"></i>
                            <p>
                                用户管理
                                <i class="right fas fa-angle-left"></i>
                            </p>
                        </a>
                        <ul class="nav nav-treeview">
                            <li class="nav-item">
                                <a href="../user/user.html" class="nav-link">
                                    <i class="far fa-user nav-icon"></i>
                                    <p>会员管理</p>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a href="./address.html" class="nav-link active">
                                    <i class="far fa-address-book nav-icon"></i>
                                    <p>收货地址管理</p>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a href="./history.html" class="nav-link">
                                    <i class="far fa-history nav-icon"></i>
                                    <p>搜索历史</p>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a href="./feedback.html" class="nav-link">
                                    <i class="far fa-info  nav-icon"></i>
                                    <p>意见反馈</p>
                                </a>
                            </li>
                        </ul>
                    </li>
                    <li class="nav-item">
                        <a href="#" class="nav-link">
                            <i class="nav-icon fas fa-copy"></i>
                            <p>
                                商城管理
                                <i class="right fas fa-magic"></i>
                                <!--                <i class="fas fa-angle-left right"></i>-->
                                <!--                <span class="badge badge-info right">6</span>-->
                            </p>
                        </a>
                        <ul class="nav nav-treeview">
                            <li class="nav-item">
                                <a href="../mall/order.html" class="nav-link">
                                    <i class="far fa-circle nav-icon"></i>
                                    <p>订单管理</p>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a href="/views/admin/mall/goods.html" class="nav-link">
                                    <i class="far fa-circle nav-icon"></i>
                                    <p>商品管理</p>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a href="../mall/common-question.html" class="nav-link">
                                    <i class="far fa-circle nav-icon"></i>
                                    <p>通用问题</p>
                                </a>
                            </li>
                        </ul>
                    </li>
                    <li class="nav-item">
                        <a href="#" class="nav-link">
                            <i class="nav-icon fas fa-chart-pie"></i>
                            <p>
                                推广管理
                                <i class="right fas fa-angle-left"></i>
                            </p>
                        </a>
                        <ul class="nav nav-treeview">
                            <li class="nav-item">
                                <a href="../advertisement/ad.html" class="nav-link">
                                    <i class="far fa-adversal nav-icon"></i>
                                    <p>广告管理</p>
                                </a>
                            </li>
                        </ul>
                    </li>
                    <li class="nav-item">
                        <a href="#" class="nav-link">
                            <i class="nav-icon fas fa-receipt"></i>
                            <p>
                                系统管理
                                <i class="fas fa-angle-left right"></i>
                            </p>
                        </a>
                        <ul class="nav nav-treeview">
                            <li class="nav-item">
                                <a href="../system/administrator.html" class="nav-link">
                                    <i class="far fa-user nav-icon"></i>
                                    <p>管理员</p>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a href="" class="nav-link">
                                    <i class="far fa-info-circle nav-icon"></i>
                                    <p>通知管理(未实现)</p>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a href="../system/Cloud-Object-Storage.html" class="nav-link">
                                    <i class="far fa-store-alt nav-icon"></i>
                                    <p>对象存储</p>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a href="" class="nav-link">
                                    <i class="far fa-paper-plane nav-icon"></i>
                                    <p>操作日志(未实现)</p>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a href="../system/role.html" class="nav-link">
                                    <i class="far fa-user nav-icon"></i>
                                    <p>角色管理</p>
                                </a>
                            </li>
                        </ul>
                    </li>
                    <li class="nav-item">
                        <a href="#" class="nav-link">
                            <i class="nav-icon fas fa-edit"></i>
                            <p>
                                配置管理
                                <i class="fas fa-angle-left right"></i>
                            </p>
                        </a>
                        <ul class="nav nav-treeview">
                            <li class="nav-item">
                                <a href="../configuration/mall.html" class="nav-link">
                                    <i class="far fa-circle nav-icon"></i>
                                    <p>商城配置</p>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a href="" class="nav-link">
                                    <i class="far fa-circle nav-icon"></i>
                                    <p>订单配置(未实现)</p>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a href="" class="nav-link">
                                    <i class="far fa-circle nav-icon"></i>
                                    <p>运费配置(未实现)</p>
                                </a>
                            </li>
                        </ul>
                    </li>
                </ul>
            </nav>
            <!-- /.sidebar-menu -->
        </div>
        <!-- /.sidebar -->
    </aside>

    <!-- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@-->
    <!--  以上均为一致，仅需要微调即可使用-->

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">
                        <h1>收货地址管理</h1>
                    </div>
                    <div class="col-sm-6">
                        <ol class="breadcrumb float-sm-right">
                            <li class="breadcrumb-item"><a href="#">首页</a></li>
                            <li class="breadcrumb-item active">用户管理</li>
                        </ol>
                    </div>
                </div>
            </div><!-- /.container-fluid -->
        </section>
        <!-- Main content -->
        <section class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-header">
                                <h3 class="card-title">收货地址管理</h3>
                            </div>
                            <div class="left  col-2">
                                <button @click="exportAllUserInfos()" class="btn btn-block btn-success">导出
                                </button>
                            </div>
                            <!-- /.card-header -->
                            <div class="card-body">
                                <table id="example1" class="table table-bordered table-striped">
                                    <thead>
                                    <tr>
                                        <th>id</th>
                                        <th>用户名</th>
                                        <th>联系人</th>
                                        <th>手机号</th>
                                        <th>详细地址</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr v-for="(i,index) of pageInfo.list" role="row">
                                        <td>{{i.address.id}}</td>
                                        <td>{{i.user.username}}</td>
                                        <td>{{i.address.name}}</td>
                                        <td>{{i.address.mobile}}</td>
                                        <td>{{i.address.addressDetail}}</td>
                                        <td>
                                            <button type="button" @click="queryAddressById(i.address.id)"
                                                    class=" btn btn-block btn-primary " data-toggle="modal"
                                                    data-target="#myModal">修改
                                            </button>
                                            <button type="button" @click="setDeletedAddressId(i.address.id)"
                                                    class=" btn btn-block btn-danger " data-toggle="modal"
                                                    data-target="#deleteModal">删除
                                            </button>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                                <div class="row">
                                    <div class="col-sm-12 col-md-7">
                                        <div class="dataTables_paginate paging_simple_numbers" id="example1_paginate">
                                            <ul class="pagination">
                                                <li class="paginate_button page-item previous disabled "
                                                    v-if="pageInfo.hasPreviousPage"

                                                    id="example1_previous"
                                                    @click="this.retrieveAddressByPageAndPageSize(pageInfo.prePage,pageInfo.pageSize)">
                                                    <a href="#" aria-controls="example1"
                                                       data-dt-idx="0" tabindex="0"
                                                       class="page-link">上一页</a>
                                                </li>
                                                <li @click="this.retrieveAddressByPageAndPageSize(item,pageInfo.pageSize)"
                                                    v-for="item of pageInfo.navigatepageNums"
                                                    class="paginate_button page-item"
                                                    :class="item===pageInfo.pageNum?'active':''" :key="item">
                                                    <a href="#"
                                                       aria-controls="example1"
                                                       data-dt-idx="item"
                                                       tabindex="0"
                                                       class="page-link">{{item}}</a>
                                                </li>
                                                <li v-if="pageInfo.hasNextPage"
                                                    @click="this.retrieveAddressByPageAndPageSize(pageInfo.nextPage,pageInfo.pageSize)"
                                                    class="paginate_button page-item next disabled" id="example1_next">
                                                    <a href="#" aria-controls="example1" data-dt-idx="2" tabindex="0"
                                                       class="page-link">下一页</a>
                                                </li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                                <div class="modal fade" id="myModal"
                                     aria-hidden="true">
                                    <div class="modal-dialog">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal"
                                                        aria-label="Close">
                                                    <span aria-hidden="true">&times;</span>
                                                </button>
                                                <h4 class="modal-title"></h4>
                                            </div>
                                            <div class="modal-body">
                                                <div style="">
                                                    <div class="card-body">
                                                        <div class="form-group">
                                                            <label for="exampleInputEmail1">用户名</label>
                                                            <input type="email" class="form-control"
                                                                   id="exampleInputEmail1"
                                                                   v-model="theAddress.user.username"
                                                                   disabled>
                                                        </div>
                                                        <div class="form-group">
                                                            <label for="phone">联系人</label>
                                                            <input type="text" class="form-control"
                                                                   id="phone"
                                                                   v-model="theAddress.address.name">
                                                        </div>

                                                        <div class="form-group">
                                                            <label for="role">手机号</label>
                                                            <input type="text" class="form-control"
                                                                   id="role"
                                                                   v-model="theAddress.address.mobile">
                                                        </div>
                                                        <div class="form-group">
                                                            <label for="role">详细地址</label>
                                                            <input type="text" class="form-control"
                                                                   id="addressDetail"
                                                                   v-model="theAddress.address.addressDetail">
                                                        </div>
                                                    </div>
                                                    <!-- /.card-body -->
                                                    <div class="card-footer">
                                                        <button type="button" class="btn btn-default"
                                                                data-dismiss="modal">取消
                                                        </button>
                                                        <button type="button" class="btn btn-primary"
                                                                @click="updateAddressById()">修改
                                                        </button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="modal fade" id="deleteModal"
                                     aria-hidden="true">
                                    <div class="modal-dialog">
                                        <div class="modal-content">
                                            <div class="modal-body">
                                                <div style="">
                                                    <!-- /.card-body -->
                                                    <div class="card-footer">
                                                        <button type="button" class="btn btn-default"
                                                                data-dismiss="modal">取消
                                                        </button>
                                                        <button type="button" class="btn btn-danger"
                                                                @click="deleteAddressById()">删除
                                                        </button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- /.card-body -->
                        </div>
                        <!-- /.card -->
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.container-fluid -->
        </section>
        <!-- /.content -->
    </div>
    <!--  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@-->
    <!--  以下均为一致，仅需微调即可使用-->
    <!-- /.content-wrapper -->
    <footer class="main-footer">
        <strong>Copyright &copy; 2020 <a href="">MALL</a></strong>
        All rights reserved.
        <div class="float-right d-none d-sm-inline-block">
            <b>Version</b> v1.0.0
        </div>
    </footer>


    <!-- Control Sidebar -->
    <aside class="control-sidebar control-sidebar-dark">
        <!-- Control sidebar content goes here -->
    </aside>
    <!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->


<!-- jQuery -->
<script src="../../plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="../../dist/js/adminlte.min.js"></script>
<script src="/views/admin/js/common.js"></script>
<!-- Page specific script -->

<script type="text/javascript">
    var data = {
        pageInfo: {
            endRow: 8,
            firstPage: 1,
            hasNextPage: true,
            hasPreviousPage: false,
            isFirstPage: true,
            isLastPage: false,
            lastPage: 8,
            list: [],
            navigateFirstPage: 1,
            navigateLastPage: 8,
            navigatePages: 8,
            navigatepageNums: [],
            nextPage: 2,
            pageNum: 1,
            pageSize: 5,
            pages: 12,
            prePage: 0,
            size: 8,
            total: -1,
        },
        keyWord: "",
        deletedAddressId: -1,
        theAddress: {
            user: {},
            address: {}
        },
        currentUser: {}
    };
    var methods = {
        setDeletedAddressId: function (id) {
            this.deletedAddressId = id;
            this.deletedAddressId = id;
        },
        deleteAddressById: function () {
            if (this.deletedAddressId === -1) {
                return;
            }
            console.log("delete address ->" + this.deletedAddressId)
            axios.delete("/address/delete/" + this.deletedAddressId, {
                headers: {
                    Authorization: adminAccessToken
                }
            })
                .then(function (response) {
                    if (response.data.code === 200) {
                        console.log("删除一个地址成功！");
                        retrieveAddressByPageAndPageSize(this.app.pageInfo.pageNum, this.app.pageInfo.pageSize);
                        $("#deleteModal").modal("hide");
                    }
                }).catch(function (err) {
                console.log(err);
            })
            $("#deleteModal").modal("hide");
        },
        exportAllUserInfos: function () {
            alert("导出模块之后一起加上@");
        },
        queryAddressById: function (id) {
            axios.get("/address/queryAddressById/" + id, {
                headers: {
                    Authorization: adminAccessToken
                }
            })
                .then(function (response) {
                    console.log(response.data);
                    if (response.data.code === 200) {
                        this.app.theAddress = response.data.data;
                    }
                })
                .catch(function (err) {
                    console.log(err);
                })
        },
        updateAddressById: function (id) {
            console.log("修改地址信息！");
            console.log(this.theAddress);
            axios.post("/address/updateAddressById", {
                id: this.theAddress.address.id,
                // username: this.theUser.username,
                name: this.theAddress.address.name,
                mobile: this.theAddress.address.mobile,
                addressDetail: this.theAddress.address.addressDetail
            },{
                headers:{
                    Authorization:adminAccessToken
                }
            }).then(function (response) {
                if (response.data.code === 200) {
                    alert("修改成功！!!");
                    $("#myModal").modal("hide");
                    this.retrieveAddressByPageAndPageSize(this.app.pageInfo.pageNum, this.app.pageInfo.pageSize);
                    // this.mounted();
                }
            }).catch(function (err) {
                console.log(err);
            });
        },
        uploadAdminAvatar: function (event) {
            updateAdminAvatar(event);
        }
    };
    var computed = {};
    var mounted = function () {
        console.log("初始化第一页的地址");
        retrieveAddressByPageAndPageSize(this.pageInfo.pageNum, this.pageInfo.pageSize);
        retrieveAdminByToken();
    }

    var
        created = function () {
        };

    var app = new Vue({
        el: "#app",
        data: data,
        methods: methods,
        computed: computed,
        created: created,
        mounted: mounted
    });
    //----------@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
</script>

</body>
</html>
